{{- /*
GitHub organization.

@param {string} (positional parameter 0) Organization name on GitHub.

@returns {template.HTML}

@examples

  {{< gh-org "github" >}}
*/ -}}

{{- if (.Get 0) -}}

    {{ $orgs := (split (.Get 0) "|") }}
    {{ $api := (site.Params.api) }}
    {{ $ts := (now.Unix) }}
    {{ $headers := (dict
    "User-Agent" ($api.user_agent)
    "Authorization" (printf "Bearer %s" (($api.github.token) | base64Decode))
    ) }}

    <div class="shortcode shortcode-{{ ($.Name) }} mb-3">
      <div class="row row-cols-1 row-cols-lg-2 g-3">
          {{ range ($orgs) }}
              {{ $org := (getJSON ($api.github.url) "/orgs/" . "?ts=" ($ts) ($headers)) }}
              <div class="col">
                <div class="card">
                  <div class="row g-0">
                      {{ if ($org.avatar_url) }}
                        <div class="col-md-4 p-1">
                          <a class="d-block" href="{{ ($org.html_url) }}" target="_blank" rel="noopener nofollow">
                            <img class="card-img"
                                 src="{{ ($org.avatar_url) }}"
                                 alt="{{ (($org.name) | default ($org.login)) }}" loading="lazy"/>
                          </a>
                        </div>
                      {{ end }}
                    <div class="col">
                      <div class="card-body h-100">
                        <div class="d-flex flex-column h-100">
                          <div class="flex-shrink-0">
                            <h5 class="card-title">
                              <a href="{{ ($org.html_url) }}" target="_blank" rel="noopener nofollow">
                                  {{ (($org.name) | default ($org.login)) }}
                              </a>
                            </h5>
                              {{ if ($org.description) }}
                                <p class="card-text">{{ (($org.description) | plainify) }}</p>
                              {{ end }}
                          </div>
                          <div class="mt-auto">
                            <div class="row row-cols-auto g-2 mt-3">
                              <div class="col" data-bs-tooltip data-bs-title='{{ (i18n "sc.github.org.repos") }}'>
                                <a class="btn btn-light btn-sm" href="{{ ($org.html_url) }}"
                                   target="_blank" rel="noopener nofollow"
                                   role="button" aria-label='{{ (i18n "sc.github.org.repos") }}'>
                                  <i class="fas fa-book fa-fw me-1"></i>
                                    {{ ($org.public_repos) }}
                                </a>
                              </div>
                                {{ if ($org.blog) }}
                                  <div class="col" data-bs-tooltip data-bs-title='{{ (i18n "sc.github.org.blog") }}'>
                                      {{ $url := (urls.Parse ($org.blog)) }}{{ $scheme := "http://" }}
                                      {{ if ($url.Scheme) }}{{ $scheme = "" }}{{ end }}
                                    <a class="btn btn-light btn-sm" href="{{ ($scheme) }}{{ ($org.blog) }}"
                                       target="_blank" rel="noopener nofollow"
                                       role="button" aria-label='{{ (i18n "sc.github.org.blog") }}'>
                                      <i class="fas fa-globe fa-fw"></i>
                                    </a>
                                  </div>
                                {{ end }}
                                {{ if ($org.twitter_username) }}
                                  <div class="col" data-bs-tooltip data-bs-title='{{ (i18n "sc.github.org.twitter") }}'>
                                    <a class="btn btn-light btn-sm" href="https://twitter.com/{{ ($org.twitter_username) }}"
                                       target="_blank" rel="noopener nofollow"
                                       role="button" aria-label='{{ (i18n "sc.github.org.twitter") }}'>
                                      <i class="fab fa-twitter fa-fw"></i>
                                    </a>
                                  </div>
                                {{ end }}
                                {{ if ($org.email) }}
                                  <div class="col" data-bs-tooltip data-bs-title='{{ (i18n "sc.github.org.email") }}'>
                                    <a class="btn btn-light btn-sm" href="mailto:{{ ($org.email) }}"
                                       target="_blank" rel="noopener nofollow"
                                       role="button" aria-label='{{ (i18n "sc.github.org.email") }}'>
                                      <i class="fas fa-envelope-open-text fa-fw"></i>
                                    </a>
                                  </div>
                                {{ end }}
                            </div>
                          </div>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
          {{ end }}
      </div>
    </div>

{{- else -}}

    {{ (partial "alerts/no_params" .) }}

{{- end -}}
